﻿using DddCms.Models.UIComponent.Window;
using System.Web.WebPages;
using System;

namespace DddCms.Models.UIComponent.Login
{

    public class WindowViewModelBuilder
    {
        public WindowViewModel WindowViewModel { get; set; }

        public WindowViewModelBuilder()
        {
            WindowViewModel = new WindowViewModel();
        }
        public WindowViewModelBuilder Title(string title)
        {
            WindowViewModel.Title = title;
            return this;
        }
        public WindowViewModelBuilder Width(string width)
        {
            WindowViewModel.Width = width;
            return this;
        }
        public WindowViewModelBuilder Position(WindowPositionViewModel position)
        {
            if (WindowViewModel.MaxWidth != 0 && position != WindowPositionViewModel.Auto)
            {
                throw new Exception("Max size is impossible with custom position");
            }
            WindowViewModel.Position = position;
            return this;
        }

        public WindowViewModelBuilder MaxWidth(int maxWidth)
        {
            if (maxWidth != 0 && WindowViewModel.Position == WindowPositionViewModel.Auto)
            {
                throw new Exception("Max size is impossible with custom position");
            }
            WindowViewModel.MaxWidth = maxWidth;
            return this;
        }
        public WindowViewModelBuilder Content(Func<object, HelperResult> f)
        {
            WindowViewModel.Content = f(null).ToString();
            return this;
        }
        public WindowViewModelBuilder Content(Func<object, HelperResult> f, string suite)
        {
            WindowViewModel.Content = f(null).ToString() + suite;
            return this;
        }
        public WindowViewModelBuilder Content(string f)
        {
            WindowViewModel.Content = f;
            return this;
        }
        public WindowViewModel Build()
        {
            if (WindowViewModel.MaxWidth == 0)
            {
                if (WindowViewModel.Position == WindowPositionViewModel.Auto)
                    throw new Exception("une window en position auto doit avoir une taille max");
            }
            return WindowViewModel;
        }

        public WindowViewModelBuilder Style(string style)
        {
            WindowViewModel.Style = style;
            return this;
        }
    }
}